﻿using Newtonsoft.Json;
using System;

namespace Learun.Application.TwoDevelopment.ZZDT_EC
{
    internal class SignalStatusConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return true;
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var dec = reader.Value?.ToString();
            switch (dec)
            {
                case "01":
                    return WireGroupStatusEnum.ToDelete;
                case "02":
                    return WireGroupStatusEnum.New;
                case "03":
                    return WireGroupStatusEnum.Used;
                case "04":
                    return WireGroupStatusEnum.Confirmed;
                case "05":
                    return WireGroupStatusEnum.Reopen;
            }
            return WireGroupStatusEnum.New;
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            WireGroupStatusEnum? dec = value as WireGroupStatusEnum?;
            switch (dec.Value)
            {
                case WireGroupStatusEnum.ToDelete:
                    writer.WriteValue("01");
                    break;
                case WireGroupStatusEnum.New:
                    writer.WriteValue("02");
                    break;
                case WireGroupStatusEnum.Used:
                    writer.WriteValue("03");
                    break;
                case WireGroupStatusEnum.Confirmed:
                    writer.WriteValue("04");
                    break;
                case WireGroupStatusEnum.Reopen:
                    writer.WriteValue("05");
                    break;
            }
        }
    }
}
